//
//  IManager+ModuleRecommendFoodList.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-21.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "IManager+ModuleRecommendFoodList.h"
#import "NetUrlDefines.h"
#import "RequestUtlity.h"
#import "FrameworkRelativeDefines.h"
#import "NSString+NSString_Ex_.h"
#import "RCRecommendFoodListDataModel.h"
#import "GloableEngineService.h"

@implementation IManager(ModuleRecommendFoodList)

-(int64_t)requestFoodTypeList:(id<IManagerDelegate>)delegate{
    
    NSString *urlSuffix = kRCRecommendFoodTypeListPrefix;
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    
    KFLog(@"request url %@",url);
    
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCRecommendFoodTypeDataModel class]
                                                     withDataDelegate:delegate];
}

-(int64_t)requestFoodListInfo:(NSString *)cityID
                 withFoodType:(NSString *)foodType
                       withPn:(NSInteger)pn
                 withDistance:(NSInteger )distance
        withSoretedType:(kMerchantsSortedType)sortedType
                 withDelegate:(id<IManagerDelegate>)delegate{
    
    if ([NSString stringIsNullOrEmpty:foodType]) {
        return kInvalidRequestId;
    }
    CLLocation *coor = [[GloableEngineService sharedInstance] locationInfo];
    
    
    // 异步获取数据
    
    NSString *urlSuffix = nil;
    
    NSString *sortType = nil;
    if (sortedType == kSortedType_Default) {
        sortType = @"default";
    }else if (sortedType == kSortedType_Distance){
        sortType = @"distance";
    }else if (sortedType == kSortedType_Price){
        sortType = @"price";
    }
    
   
    urlSuffix = [NSString stringWithFormat:kRCRecommendFoodListPrefix,cityID,pn,10,coor.coordinate.latitude,coor.coordinate.longitude,foodType,distance,sortType];
    
    
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
//    url = @"http://223.4.99.93/www.17ruyi.com/api.php?op=app_nearby&action=foodlist&cityid=3361&pn=0&rn=5&lat=39.97252&lon=116.332161";
    KFLog(@"request url %@",url);
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCRecommendAllFoodListDataModel class]
                                                     withDataDelegate:delegate];
}

@end
